package com.example.hotel_manage.web.controller.admin;

<<<<<<< HEAD
=======

>>>>>>> d362211627a47461162200734711043168a39386

/**
 * 【管理员】控制器
 */
@RestController
@RequestMapping(WebConst.ModulePath.ADMIN + "/admin")
public class AdminController extends AbstractController implements AdminAPI {

    @Autowired
    private AdminService adminService;

    @Override
    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    public ResponseEntity<AdminShowVO> save(@Valid @RequestBody AdminAddDTO adminAddDTO) throws Exception {
        AdminPO admin = adminService.save(adminAddDTO);
        return ResponseEntity.created(new URI(WebConst.ModulePath.ADMIN + "/admin/" + admin.getId()))
                .body(AdminMapper.INSTANCE.toShowVO(admin));
    }

    @Override
    @PutMapping
    public ResponseEntity<AdminShowVO> update(@Valid @RequestBody AdminUpdateDTO adminUpdateDTO) {
        AdminPO admin = adminService.update(adminUpdateDTO);
        return ResponseEntity.ok(AdminMapper.INSTANCE.toShowVO(admin));
    }

    @Override
    @GetMapping
    public ResponseEntity<PageVO<AdminListVO>> list(@Valid AdminQO adminQO) {
        PageVO<AdminListVO> page = adminService.list(adminQO);
        return ResponseEntity.ok(page);
    }

    @Override
    @GetMapping(value = "/{id}")
    public ResponseEntity<AdminShowVO> show(@PathVariable Integer id) {
        AdminShowVO adminShowVO = adminService.show(id);
        return ResponseEntity.ok(adminShowVO);
    }

    @Override
    @DeleteMapping(value = "/{id}")
    public ResponseEntity<Integer> delete(@PathVariable Integer id) {
        int count = adminService.delete(id);
        return ResponseEntity.ok(count);
    }

    @Override
    @DeleteMapping
    public ResponseEntity<Integer> deleteBatch(@RequestBody Integer[] id) {
        if (ArrayUtils.isEmpty(id)) {
            throw new BusinessException(ErrorCode.PARAM_IS_NULL);
        }
        int count = adminService.delete(id);
        return ResponseEntity.ok(count);
    }

}


